package tcp.prop;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertyManager {

	public static JobConfig loadProperty(InputStream file) {
		JobConfig jobConf = new JobConfig();
		Properties prop = new Properties();
		try {
			prop.load(file);
		} catch (IOException e) {
			e.printStackTrace();
		}

		if (prop.getProperty("CONNECTION_LIMIT") != null) {
			jobConf.setConnectionLimit(Integer.parseInt(prop.getProperty("CONNECTION_LIMIT")));
		}
		if (prop.getProperty("SOURCE_PORT") != null) {
			jobConf.setSourcePort(Integer.parseInt(prop.getProperty("SOURCE_PORT")));
		}
		if (prop.getProperty("WELCOME_PORT") != null) {
			jobConf.setWelcomePort(Integer.parseInt(prop.getProperty("WELCOME_PORT")));
		}
		if (prop.getProperty("SOURCE_IP") != null) {
			jobConf.setSourceIp(prop.getProperty("SOURCE_IP"));
		}

		return jobConf;
	}
}